import { EntityState, EntityStore, PaginatorPlugin, QueryEntity, StoreConfig } from '@datorama/akita';
import { produce } from 'immer'; 
import { VISIBILITY_FILTER } from "@/models/commonType";
import { OrgsItem } from '@/models/request/userReq';

export interface OrgFollowEntity extends EntityState<OrgsItem, string> {
  filter: VISIBILITY_FILTER;
}

@StoreConfig({ name: "org_follows", producerFn: produce, idKey: 'org_no' })
export class OrgFollowStore extends EntityStore<OrgFollowEntity> {
  constructor() {
    super({
      filter: VISIBILITY_FILTER.SHOW_ALL,
    });
  }
}

export class OrgFollowQuery extends QueryEntity<OrgFollowEntity> {
  filter$ = this.select((state) => state.filter);

  constructor(protected store: OrgFollowStore) {
    super(store);
  }
}

export const makeStore = (): [OrgFollowStore, OrgFollowQuery, PaginatorPlugin<OrgFollowEntity>] => {
  const store = new OrgFollowStore();
  const query = new OrgFollowQuery(store);

  const org_follows_paginator = new PaginatorPlugin(query)
    .withControls()
    .withRange();

  return [store, query, org_follows_paginator];
};
